package org.butterfly.irms.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger3 config
 * <a href="http://localhost:8180/irms/swagger-ui/index.html">swagger API page</a>
 *
 * @author drake
 * @since 2021/9/5
 */
@Configuration
@EnableOpenApi
public class Swagger3Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.butterfly.irms"))
                .paths(PathSelectors.any())
                .build();
    }

    // apiInfo, include: title, contact, version and so on.
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("IT Resource Management System API Document")
                .description("any doubt, pls contact developer.")
                .contact(new Contact("Drake", "", ""))
                .version("1.0")
                .build();
    }
}
